
import multiprocessing
import os


def sub_process1(name):
    print(f'子进程pid={os.getpid()}, ppid={os.getppid()}, name={name}')
    print(f'子进程的别名：{multiprocessing.current_process().name}')


def sub_process2(name):
    print(f'子进程pid={os.getpid()}, ppid={os.getppid()}, name={name}')
    print(f'子进程的别名：{multiprocessing.current_process().name}')


if __name__ == "__main__":
    print('主进程开始......')

    for i in range(1, 4):
        p1 = multiprocessing.Process(target=sub_process1, args=(f'进程{i}',))
        p1.start()
        p2 = multiprocessing.Process(target=sub_process2, args=(f'进程{i}',))
        p2.start()
        # p1.run()
        # p2.run()
        p1.terminate()
        p2.terminate()

    print('主进程结束......')
